package LeetcodeTest_twenty_four;
//213.打家劫舍II

import java.util.Arrays;

public class robs
{
    public static void main(String[] args)
    {
        int[] rob={2,7,9,3,1};
        System.out.println(solution.rob(rob));
    }
}
class solution
{
    public static int rob(int[] nums)
    {
        int n=nums.length;
        int[] num1= Arrays.copyOfRange(nums,0,n-1);
        int[] num2= Arrays.copyOfRange(nums,1,n);
        return Math.max(robs(num1),robs(num2));
    }
    public static int robs(int[] nums)
    {
        int i;
        int n = nums.length;
        int[] dp = new int[n];
        if (n == 0)
            return 0;
        for (i = 0; i < n; i++)
        {
            if(i==0)
                dp[i]=nums[0];
            else if(i==1)
                dp[i] = Math.max(nums[0], nums[1]);
            else
                dp[i]=Math.max(dp[i-2]+nums[i],dp[i-1]);
        }
        return dp[n-1];
    }
}